﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExaminationSys.DataAccess;
using ExaminationSys.DataAccess.Entity;
using ExaminationSys.DataAccess.Repository;

namespace ExaminationSys
{
    public partial class StudentCenter : BasePage
    {
        public string LoginName { get; set; }

        private static readonly LoginLogService Proxy = ObjectFactory<LoginLogService>.Create();
        private static readonly TeacherInfoService ProxyTeacherInfo = ObjectFactory<TeacherInfoService>.Create();
        private static readonly SubSectionInfoService ProxySubSection = ObjectFactory<SubSectionInfoService>.Create();
        private static readonly SubSectionDetailInfoService ProxySubSectionDetailInfo = ObjectFactory<SubSectionDetailInfoService>.Create();
        private static readonly SectionInfoService ProxySectionInfo = ObjectFactory<SectionInfoService>.Create();
        private static readonly SectionPaperService ProxySectionPaperService = ObjectFactory<SectionPaperService>.Create();
        private static readonly StudentTestHistoryService ProxyPaperInfoStudentTestHistory = ObjectFactory<StudentTestHistoryService>.Create();

        public List<SubSectionInfo> SubSectionInfoCollection = new List<SubSectionInfo>();

        public List<SubSectionDetailInfo> GetListBySubSectionId(Guid subSectionid)
        {
            return ProxySubSectionDetailInfo.GetListBySubSectionId(subSectionid);
        }

        public StudentTestHistory GetStudentPaper(Guid paperId)
        {
            return ProxyPaperInfoStudentTestHistory.GetStudentPaper(UserID, paperId);
        }

        //级别名称
        public string LevelName { get; set; }
        public string SectionId { get; set; }
        public int KnowlegdeLevel = 0;
        public StringBuilder htmlStr = new StringBuilder();
        public SectionInfo SectionInfo = new SectionInfo();
        public StringBuilder htmlStrSectionInfo = new StringBuilder();
        public Guid UserID = Guid.Empty;

        public List<SectionPaper> GetSectionPaperBySectionId(Guid sectionId)
        {
            return ProxySectionPaperService.GetPaperInfoBySectionId(sectionId);
        }

        public PaperFeedback GetStudentTestComment(Guid paperid)
        {
          return  ProxyPaperInfoStudentTestHistory.GetStudentTestComment(UserID, paperid);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var sectionIdTmp = Request["sectionid"];
            var sectionId = Guid.Empty;
            if(!Guid.TryParse(sectionIdTmp,out sectionId))
            {
                Response.Redirect("error.aspx");
            }

            SectionId = sectionIdTmp;
            KnowlegdeLevel = base.GetCurrentStudentLevel();
            if (!IsPostBack)
            {
                base.ResetSession();
                var loginInfo = Session["StudentInfo"] as Student;
                if (loginInfo != null)
                {
                    UserID = loginInfo.ID;
                    SectionInfo = ProxySectionInfo.Get(sectionId);
                    LoginName = loginInfo.UserName;
                    if (KnowlegdeLevel == 0) KnowlegdeLevel = (int)EnumLevel.初级;
                    LevelName = Enum.GetName(typeof(EnumLevel), KnowlegdeLevel);
                    SubSectionInfoCollection = ProxySubSection.GetListByKnowlegdeLevel(KnowlegdeLevel, SectionId);


                }
                else
                {
                    Response.Redirect("Index.aspx");
                }

            }
        }
    }
}